import QtQuick 2.7
import QtQuick.Controls 2.5

import "./widgets" as Widgets
import "./layouts" as Layouts

/////////////////////////////// 资料输入页面 ////

Rectangle {
    id: root

    signal back()
    signal backWithCode(string code)

    ////////

    Component.onCompleted: {
        tmrFake.start()
    }

    Timer {
        id: tmrFake
        interval: 300
        repeat: true
        property int count: 0

        onTriggered: {
            switch (count) {
                case 0: listModel.append({"name":"POCT_0003"}); break;
                case 1: listModel.append({"name":"POCT_0045"}); break;
                case 2: listModel.append({"name":"POCT_001D"}); break;
                default: tmrFake.stop()
            }

            count++;
        }
    }

    ///////////////////////////////////////// UI ////
    Layouts.TopLayout {
        id: toolBar
        z: 100
        width: parent.width
        height: root.height * 0.1
        title: qsTr("选择连接设备")

        onClickedBack: root.back()
    }

    Item {
        width: parent.width
        height: parent.height - toolBar.height
        y: toolBar.height

        //================================= 数据列表 ====
        ListView {
            anchors.horizontalCenter: parent.horizontalCenter
            width: parent.width
            height: parent.height
            clip: true

            model: ListModel {
                id: listModel
            }

            delegate: Rectangle {
                width: parent.width
                height: root.height * 0.09
                color: index % 2 == 0 ? "#ccc" : "#e1e1e1"

                Text {
                    id: txtItemName
                    width: parent.width
                    height: parent.height
                    horizontalAlignment: Text.AlignHCenter
                    verticalAlignment: Text.AlignVCenter
                    font.pixelSize: height * 0.35
                    text: name
                }

                MouseArea {
                    anchors.fill: parent
                    onClicked: {
                        backWithCode(txtItemName.text)
                    }
                }
            }

            ScrollBar.vertical: ScrollBar {}

        } //---- ListView
    }

}
